package com.tenement.service.impl;

import java.util.List;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.alibaba.fastjson.JSONObject;
import com.tenement.mybatis.dao.AdminMapper;
import com.tenement.mybatis.entity.Admin;
import com.tenement.service.interfaces.IAdminService;
import com.tenement.utils.page.PageUtil;

@Service("IAdminService")
public class AdminServiceImpl implements IAdminService {

	@SuppressWarnings("unused")
	private static final Log logger = LogFactory.getLog(AdminServiceImpl.class);

	@Autowired
	private AdminMapper adminMapper;

	/**
	 * 获取管理员列表
	 */
	@Override
	public  List<Admin> getAdminList() {
		List<Admin> adminList = adminMapper.getAdminListAll();
		return adminList;
	}

	/**
	 * 分页获取管理员列表
	 */
	@Override
	public JSONObject getAdminListPage(String aname, String account, int pageIndex, int pageSize) {
		PageUtil pageUtil = new PageUtil();
		pageUtil.setPageSize(pageSize);
		pageUtil.setPageIndex(pageIndex);
		int startRecord = pageUtil.getStartRecord();
		Admin admin = new Admin();
		int totalRecord = adminMapper.getTotalRecords(admin);
		pageUtil.setTotalrecord(totalRecord);// 传入了总记录数，同时设置了总页数
		List<Admin> adminList = adminMapper.getAdminListPage(aname, account, startRecord, pageSize);
		JSONObject jsonObject = new JSONObject();
		jsonObject.put("adminList", adminList);
		jsonObject.put("pageCount", pageUtil.getPageCount());
		return jsonObject;
	}

	/**
	 * 管理员登录
	 */
	@Override
	public Admin loginAdmin(Admin admin) {
		return adminMapper.loginAdmin(admin);
	}

	/**
	 * 获取总记录数
	 */
	@Override
	public int getTotalRecords(Admin admin) {
		return adminMapper.getTotalRecords(admin);
	}

	@Override
	public boolean addAdmin(Admin admin) {
		// TODO Auto-generated method stub
		return false;
	}

}
